package com.lwg.datastructure.dynamicPrograming;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @FileName: MulMaxChildNums.java
 * @author: 李炜光
 * @description:: 乘积最大子数组
 * @Date: 2022/2/21 0021
 */
public class MulMaxChildNums {

    public int maxProduct(int[] nums) {
        // 1.初始化数据
        int preMax = 1;
        int preMin = 1;
        int maxMul = nums[0];
        int length = nums.length;
        // 2.遍历数组
        for (int i = 0; i < length; i++) {
            // 因为当遇到负数时，最小的可能变最大的，最大的可能变最小的
            // 所有此时需要交换一下最大最小的数，preMax每次得到的都是最大的
            if (nums[i] < 0) {
                int temp = preMax;
                preMax = preMin;
                preMin = temp;
            }
            // 3.得到前(i-1)乘积最大的值
            preMax = Math.max(preMax * nums[i], nums[i]);
            preMin = Math.min(preMin * nums[i], nums[i]);
            maxMul = Math.max(maxMul, preMax);
        }
        return maxMul;
    }
}

class MainClass13 {
    public static int[] stringToIntegerArray(String input) {
        input = input.trim();
        input = input.substring(1, input.length() - 1);
        if (input.length() == 0) {
            return new int[0];
        }

        String[] parts = input.split(",");
        int[] output = new int[parts.length];
        for (int index = 0; index < parts.length; index++) {
            String part = parts[index].trim();
            output[index] = Integer.parseInt(part);
        }
        return output;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = in.readLine()) != null) {
            int[] nums = stringToIntegerArray(line);

            int ret = new MulMaxChildNums().maxProduct(nums);

            String out = String.valueOf(ret);

            System.out.print(out);
        }
    }
}